import asyncio
import time

# 创建一个协程
async def task1():
    print("task 1 开始")
    await asyncio.sleep(2)
    print("task 1 结束")
    return "task 1 结果"

# 创建一个协程
async def task2():
    print("task 2 开始")
    await asyncio.sleep(1)
    print("task 2 结束")
    return "task 2 结果"

# 主协程
async def main():
    # 并行运行两个协程
    result = await asyncio.gather(task1(), task2())
    print("所有任务完成：", result)

start_time = time.time()
# 运行主协程
asyncio.run(main())
end_time = time.time()
print("总耗时：", end_time - start_time)